package weather;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.Observable;
import java.util.Random;
import javax.swing.Timer;


public class WeatherData extends Observable {

    private float temperature;
    private float humidity;
    private float pressure;
    
    public WeatherData(int milisegs) {
             Timer timer = new Timer (milisegs, new ActionListener ()
         {
             public void actionPerformed(ActionEvent e)
             {
                 Random rdn = new Random();
                 float temp = (rdn.nextFloat()*50)-10;
                 float hum = (rdn.nextFloat()*30)+40;
                 float pres = rdn.nextFloat()*40;
                 setMeasurements(temp,hum,pres);                 
             }
         });
         timer.start();
    }

    public void measurementsChanged() {
        setChanged();
        notifyObservers();
    }

    public void setMeasurements(float temp, float hum, float pres) {
        this.setTemperature(temp);
        this.setHumidity(hum);
        this.setPressure(pres);
        measurementsChanged();
    }

    public float getTemperature() {
        return temperature;
    }

    public void setTemperature(float temperature) {
        this.temperature = temperature;
    }

    public float getHumidity() {
        return humidity;
    }

    public void setHumidity(float humidity) {
        this.humidity = humidity;
    }

    public float getPressure() {
        return pressure;
    }

    public void setPressure(float pressure) {
        this.pressure = pressure;
    }
}